package com.EpidemicPrevention.controller;

import com.EpidemicPrevention.pojo.Enrolled;
import com.EpidemicPrevention.service.EnrolledServiceImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;



@Controller
@RequestMapping("/EnrolledController")
public class EnrolledController {

    @Autowired
    private EnrolledServiceImpl enrolledService;

    /*
     *添加用户
     * @Prama user 实体类
     * @return
     */
    @GetMapping("/addEnrolled")
    @ResponseBody
    @CrossOrigin
    public JSON addEnrolled(Enrolled enrolled) {
        return enrolledService.addEnrolled (enrolled);
    }


    @GetMapping("/updataEnrolled")
    @ResponseBody
    @CrossOrigin
    public  JSON updataEnrolled(Enrolled enrolled){
        return enrolledService. updateEnrolled (enrolled);
    }

    /**
     * 删除用户
     *
     * @param e_id
     * @return
     */
    @GetMapping("/deleteEnrolled")
    @ResponseBody
    @CrossOrigin
    public JSON deleteEnrolled(int e_id) {
        return enrolledService.deleteEnrolled (e_id);
    }



    /**
     * 查看用户
     *
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/queryEnrolled")
    @ResponseBody
    @CrossOrigin
    public JSON queryEnrolled(@RequestParam("page") int page, @RequestParam("limit") int limit) {
        JSONObject json = new JSONObject();
        int page1 = page - 1;
        int page2 = page1 * limit;
        json.put("code", 1);
        json.put("msg", "");
        json.put("count",enrolledService.queryEnrolled (0, 100000,null).size());
        json.put("data", enrolledService.queryEnrolled (page2, limit,null));
        return json;
    }

    @GetMapping("/selectWhereEnrolled")
    @ResponseBody
    @CrossOrigin
    public JSON selectWhereEnrolled(@RequestParam("page")int page,@RequestParam("limit")int limit,@RequestParam("Keyword")String Keyword) {
        JSONObject json = new JSONObject();
        int page1 = page - 1;
        int page2 = page1 * limit;
        json.put("code", 1);
        json.put("msg", "查询成功");
        json.put("count", enrolledService.queryEnrolled (0, 100000, Keyword).size());
        json.put("data", enrolledService.queryEnrolled (page2, limit, Keyword));
        return json;
    }

}
